package com.fzy.core.system.action;

import ge.core.system.entity.Mapping;

import java.util.Date;

import com.fzy.core.system.service.DbService;
import com.fzy.core.utils.U;
import com.fzy.core.webwork.BaseAction;
import com.fzy.core.webwork.MyValidationAware;
import com.opensymphony.xwork.ModelDriven;
import com.opensymphony.xwork.Preparable;

public class MappingSaveAction extends BaseAction implements Preparable, MyValidationAware, ModelDriven {

	private static final long serialVersionUID = -55725527522956019L;
	
	String errorDispatch;
	Mapping mapping;
	DbService dbService;

	public void prepare() throws Exception {
		errorDispatch = "dispatcher:/pages/refresh-parent.jsp";
		mapping = (Mapping)validateIdAndGetEntity(request.getParameter("id"), Mapping.class);
        
		// default values
        if(mapping == null){
        	mapping = new Mapping();
    		mapping.setNameText("default");
    		mapping.setPackageText("ge");
    		mapping.setPrefixText("ru");
        }
	}

	public void validate() {

	}

	public String execute() throws Exception {
		dbService.saveEntityId(mapping);

		addActionMessage(getText("success.save"));
		return "dispatcher:/pages/refresh-parent.jsp";
	}

	public Object getModel() {
		return mapping;
	}

	public String getErrorDispatch() {
		return errorDispatch;
	}

	public void setDbService(DbService dbService) {
		this.dbService = dbService;
	}

}
